<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑项目信息</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>承揽状态</label>
                        <div class="layui-input-block">
                            <select id="lantake" name="lantake" lay-filter="lantake" ></select>
                            <p class="error" id="lantake_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>甲方名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="jiaer" class="layui-input jiaer" onclick="openPage('../public/choose_dealcom.php?dom=jiaer','80%','80%')">
                            <div class="choose_div" id="jiaer" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=jiaer','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程负责人</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="gofuer" class="layui-input gofuer" onclick="openPage('../public/choose_dealcom.php?dom=gofuer','80%','80%')">
                            <div class="choose_div" id="gofuer" key="0"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=gofuer','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">所在地</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>承揽方式</label>
                        <div class="layui-input-block">
                            <div id="lanshi"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>业务归属</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=gui_unit&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="gui_unit"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=gui_unit&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="gui_unit_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text class="takehide layui-hide">*</text>招标方式</label>
                        <div class="layui-input-block">
                            <div id="zhaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text class="takehide layui-hide">*</text>工程发布平台</label>
                        <div class="layui-input-block">
                            <div id="kailei"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">资质要求</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongzi" id="gongzi" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>工程内容</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongnei" id="gongnei" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>工程建设规模</label>
                        <div class="layui-input-block">
                            <input type="text" name="guimo" id="guimo" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text class="takehide layui-hide">*</text>中标单位</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=win_unit&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="win_unit"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=win_unit&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="win_unit_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">中标日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="windt" id="windt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">中标价(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="winfee" name="winfee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工期(天)</label>
                        <div class="layui-input-block ">
                            <input type="text" name="gongqi" id="gongqi" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">劳务分包服务费率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="ratefu" id="ratefu" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税款保证金费率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="rateshui" id="rateshui" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程合同类别</label>
                        <div class="layui-input-block">
                            <div id="gonghelei"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>

        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            name: {required: true},
            gongnei: {required: true},
            guimo: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            gongnei: {required: "请输入"},
            guimo: {required: "请输入"},
        }
    });


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_engin_edit,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $('#name').val(data.name);
                $('#number').val(data.number);

                $('#addr').val(data.addr);
                $('#windt').val(data.windt);
                $('#winfee').val(data.winfee);
                $('#gongqi').val(data.gongqi);
                $('#ratefu').val(data.ratefu);
                $('#rateshui').val(data.rateshui);
                $('#gongzi').val(data.gongzi);
                $('#gongnei').val(data.gongnei);
                $('#guimo').val(data.guimo);
                $('#explain').val(data.explain);


                if(data.jiaer){
                    set_choose_btn('jiaer',data.jiaer,data.jiaer);
                }
                if(data.win_unit_info.length > 0){
                    tan_tags_init('#win_unit', data.win_unit_info);
                }
                if(data.gui_unit_info.length > 0){
                    tan_tags_init('#gui_unit', data.gui_unit_info);
                }

                if(data.gofuer){
                    set_choose_btn('gofuer',data.gofuer,data.gofuer);
                }


                var lantake_str = '<option value="">请选择</option>';
                var lantake = res.data.lantake;
                for (var key in lantake){
                    if(data.lantake == key){
                        lantake_str += '<option value="'+key+'" selected>'+lantake[key]+'</option>';
                    }else{
                        lantake_str += '<option value="'+key+'">'+lantake[key]+'</option>';
                    }
                }
                $("#lantake").html(lantake_str);


                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(data.state == key){
                        state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                    }else{
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }
                }
                $("#state").html(state_str);





                $("#areas").val(data.areas);
                load_areas('areas', res.data.areas, 3);
                xmselect_dan('lanshi', res.data.lanshi, data.lanshi, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#lanshi").find('xm-select').removeClass('error');
                    }else{
                        $("#lanshi").find('xm-select').addClass('error');
                    }
                });
                xmselect_dan('kailei', res.data.kailei, data.kailei, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#kailei").find('xm-select').removeClass('error');
                    }else{
                        $("#kailei").find('xm-select').addClass('error');
                    }
                });
                xmselect_dan('zhaotype', res.data.zhaotype, data.zhaotype, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#zhaotype").find('xm-select').removeClass('error');
                    }else{
                        $("#zhaotype").find('xm-select').addClass('error');
                    }
                });

                xmselect_dan('gonghelei', res.data.gonghelei, data.gonghelei);


                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('select(lantake)', function(data){
            if(data.value == ''){
                $('#lantake_error').show().text('请选择');
                $('#lantake_error').parent().find('input').addClass('select_error');
            }else{
                $('#lantake_error').hide();
                $('#lantake_error').parent().find('input').removeClass('select_error');
            }

            if(data.value == 2){
                $(".takehide").removeClass('layui-hide');
            }else{
                $(".takehide").addClass('layui-hide');
            }
            render_from();
        });

        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            data.field.jiaer = get_choose_val('jiaer');
            data.field.gofuer = get_choose_val('gofuer');
            data.field.gui_unit = tan_tags_getvalue("#gui_unit", 'dept');
            data.field.win_unit = tan_tags_getvalue("#win_unit", 'dept');

            var validRes = $("#commentForm").valid();

            formValid('jiaer');
            if(data.field.jiaer == undefined || !data.field.jiaer){
                validRes = false;
            }

            if(data.field.lantake == ''){
                $('#lantake_error').show().text('请选择');
                $('#lantake_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#lantake_error').hide();
                $('#lantake_error').parent().find('input').removeClass('select_error');
            }

            if(!data.field.gui_unit){
                $("#gui_unit").parents('.tanxian').addClass('tanerror');
                $('#gui_unit_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#gui_unit").parents('.tanxian').removeClass('tanerror');
                $('#gui_unit_tanerror').text('');
            }

            if(!data.field.lanshi){
                $("#lanshi").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#lanshi").find('xm-select').removeClass('error');
            }

            if(!data.field.kailei && data.field.lantake == 2){
                $("#kailei").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#kailei").find('xm-select').removeClass('error');
            }

            if(!data.field.zhaotype && data.field.lantake == 2){
                $("#zhaotype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#zhaotype").find('xm-select').removeClass('error');
            }

            if(!data.field.win_unit && data.field.lantake == 2){
                $("#win_unit").parents('.tanxian').addClass('tanerror');
                $('#win_unit_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#win_unit").parents('.tanxian').removeClass('tanerror');
                $('#win_unit_tanerror').text('');
            }

            if(data.field.state == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }

            if(!validRes){return false;}

            data = parseMoney(data);
            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_engin_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
